import React, { useState, useEffect } from 'react';
import { Table, message } from "antd"
import { useSelector, useDispatch } from "umi"
import { onTableSelect, components } from '@/utils/commonFns/commonDispatch';
import $http from "@/services"
import Columns from '../Columns';
export default function TableLists({ data, changeDiallogValue }) {
    const userInfos = JSON.parse(localStorage.getItem("userProfile"));
    const [dialogStutus, setDialogStutus] = useState(false);
    const { effects } = useSelector(state => state.loading);
    const dispatch = useDispatch();

    const handleSave = async (obj) => {
        console.log(obj)
        // 修改数据,后重新渲染
        const data = await $http.updateSalary({
            ...obj,
            updateVal: obj.updateVal[obj.type]
        });
        changeDiallogValue();
        message.success(data.msg);

    };
    const getDetailSalary = (id) => {
        console.log(id)
        dispatch({
            type: "salary/getDetailSalary",
            payload: id
        })
    }

    const columns = Columns(handleSave, getDetailSalary);

    return (
        <>
            <Table
                components={components}
                rowClassName={() => 'editable-row'}
                bordered
                rowSelection={{ onChange: (ids) => onTableSelect(ids, dispatch) }}
                scroll={{ x: true }}
                rowKey={el => el._id}
                dataSource={data}
                pagination={false}
                columns={columns}
                loading={effects["salary/initSalaryContent"]}
            />

        </>
    );
}
